package com.godfrey.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * description : SwaggerConfig
 *
 * @author godfrey
 * @since 2020-06-03
 */
@Configuration //配置类
@EnableSwagger2 // 开启Swagger2的自动配置
@Profile({"dev","test"})
public class SwaggerConfig {

    //配置docket以配置Swagger具体参数
    @Bean
    public Docket docket() {

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("对弈")
                .select()// 通过.select()方法，去配置扫描接口,RequestHandlerSelectors配置如何扫描接口
                .apis(RequestHandlerSelectors.basePackage("com.godfrey.controller"))
                .build();
    }

    //配置文档信息
    private ApiInfo apiInfo() {
        Contact contact = new Contact("godfrey", "https://www.duiyi.xyz", "2424496907@qq.com");

        return new ApiInfo(
                "Swagger学习", // 标题
                "学习如何配置Swagger", // 描述
                "v1.0", // 版本
                "https://www.duiyi.xyz", // 组织链接
                contact, // 联系人信息
                "Apache 2.0", // 许可
                "http://www.apache.org/licenses/LICENSE-2.0", // 许可连接
                new ArrayList<>()// 扩展
        );

    }

}
